package com.cy.sp04o.order.controller;

import com.cy.pojo.Item;
import com.cy.pojo.Order;
import com.cy.pojo.User;
import com.cy.server.OrderService;
import com.cy.server.UserService;
import com.cy.sp04o.order.service.OrderServiceImpl;
import com.cy.web.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @author Chenwx
 * @date 2021/4/29 15:28
 */
@RestController
@Slf4j
public class OrederController {
    @Autowired
    private OrderService orderService;
    //获取订单
    @GetMapping("/{orderId}")
    public JsonResult<Order> getOrder(@PathVariable String orderId){
        Order order=orderService.getOrder(orderId);
        return JsonResult.ok().data(order);
    }

    //添加订单
    @GetMapping("/")
    public JsonResult<?> addOrder(){
        Order order=new Order();
        order.setId("54asd65da");
        order.setUser(new User(8,null,null));
        order.setItems(Arrays.asList(new Item[] {
                new Item(1,"商品1",1),
                new Item(2,"商品2",2),
                new Item(3,"商品3",3),
                new Item(4,"商品4",4),
        }));
        orderService.addOrder(order);
        return JsonResult.ok();
    }
}
